//
//  ViewController.m
//  进度条与滑动条
//
//  Created by My Mac on 2016/12/13.
//  Copyright © 2016年 My Mac. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

static float number = 0;
- (void)viewDidLoad {
    [super viewDidLoad];
    _lable = [[UILabel alloc]initWithFrame:CGRectMake(260, 60, 60, 40)];
    _lable.tag = 100;
    
    _lable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_lable];
    
    NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(setProgressView) userInfo:nil repeats:YES];
    [timer setFireDate:[NSDate distantPast]];
    
    [self setSlider];
    
}
#pragma mark - 进度条的应用
-(void)setProgressView
{
    //进度条的创建
    _progressView = [[UIProgressView alloc]init];
    
    //进度条的大小设置
    //进度条的高度是不可变化的(由系统默认)，这里设置的高度不起任何作用
    _progressView.frame = CGRectMake(10, 80, 240, 40);
    
    //设置进度条的风格颜色值，系统默认为蓝色的
    _progressView.progressTintColor = [UIColor redColor];
    
    //设置进度条未完成的轨迹颜色，系统默认为灰色
    _progressView.trackTintColor = [UIColor yellowColor];
    
    //设置进度条的进度值,范围为"0 ~ 1",最小值为 0，最大值为 1
    //进度条应用百分比表示:0.6 --> 60%
    _progressView.progress = number;
    
    
    _lable.text = [NSString stringWithFormat:@"%.f%%",_progressView.progress*100];
    
    //设置进度条的风格特征
    _progressView.progressViewStyle = UIProgressViewStyleBar;
    
    //将进度条添加到视图上
    [self.view addSubview:_progressView];
    
    number += 0.01;
    
}

#pragma mark - 滑动条的应用
-(void)setSlider
{
    //创建滑动条对象
    _slider = [[UISlider alloc]init];
    
    //位置设置，高度有系统默认，不可更改
    _slider.frame = CGRectMake(10, 200, 240, 40);
    
    //设置滑动条的最大值
    _slider.maximumValue = 100;
    
    //设置最小值,可以为负值
    _slider.minimumValue = 0;
    
    //设置滑动的值
    _slider.value = 30;
    
    //左侧滑动条的背景色
    _slider.minimumTrackTintColor = [UIColor yellowColor];
    
    //右侧滑动条的背景色
    _slider.maximumTrackTintColor = [UIColor blueColor];
    
    //设置滑块的颜色
    _slider.thumbTintColor = [UIColor redColor];
    
    //对滑动条添加响应事件
    [_slider addTarget:self action:@selector(pressSlider) forControlEvents:UIControlEventTouchUpInside];
    
    //添加到视图上
    [self.view addSubview:_slider];
    
}
-(void)pressSlider
{
    NSLog(@"%@",[NSString stringWithFormat:@"%.f%%",_slider.value/_slider.maximumValue*100]);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
}

@end
